#include "../Source/server.hpp"

void OnConnected(const PtrConnection &conn)
{
    DBG_LOG("New Connection:%p", conn.get());
}
void OnClosed(const PtrConnection &conn)
{
    DBG_LOG("Closed Connection:%p", conn.get());
}
void OnMessage(const PtrConnection &conn, Buffer *buf)
{
    DBG_LOG("%s", (buf->GetReadPosition()));
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "Hello World!";
    conn->Send(str.c_str(), str.size());
}


int main()
{
    TcpServer server(8500);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(2);
    server.SetMessageCallBack(OnMessage);
    server.SetClosedCallBack(OnClosed);
    server.SetConnectedCallBack(OnConnected);
    // server.SetMessageCallBack(std::bind(OnMessage, std::placeholders::_1, std::placeholders::_2));
    // server.SetClosedCallBack(std::bind(OnClosed, std::placeholders::_1));
    // server.SetConnectedCallBack(std::bind(OnConnected, std::placeholders::_1));
    // server.SetAnyEventCallBack();
    server.Start();
    return 0;
}